#!/usr/bin/env python3.0

import sys
import madsimple

if sys.argv[1]=='-debug':
	del sys.argv[1]
	import pdb
	pdb.set_trace()

if len(sys.argv)<3:
	print("{0:s} mp3file outputpcm".format(sys.argv[0]))
	sys.exit(1)

def test_filter():
	with open(sys.argv[1], "br") as rfo:
		with open(sys.argv[2], "bw") as wfo:
			print("open 2 files")
			decoder = madsimple.SimpleDecoder(rfo, 5000)
			print("create decoder")
			decoder.run()
			print("decoder started")
			#　fileioはio.BufferedReaderのインヘリタンス
			#decoder.config()

			while True:
				byte = decoder.getPCM()
				if byte==None:
					break
				#if i>30: break
				wfo.write(byte)

def output(fo, pcm_data):
	fo.write(pcm_data)

def error(fo, data):
	pass

def test_decoder():
	with open(sys.argv[1], "br") as rfo:
		with open(sys.argv[2], "bw") as wfo:
			#print("open 2 files")
			decoder = madsimple.Decoder(rfo, wfo, 5000)
			#print("create decoder")
			#print("decoder started")
			#　fileioはio.BufferedReaderのインヘリタンス
			#decoder.config() # 16bit? 2channel? 44100Hz? とか設定
			decoder.run(header=None, output=output, error=error)
			print("finished!")


#test_filter()
test_decoder()
print("exit")



